/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/


// Code -------------------------------
RUM_FXD_Payload = {
	_payload = [];
	private "_payload";
	_munlist = [RUM_TypeFXDM1_IDC,RUM_TypeFXDM2_IDC,RUM_TypeFXDM3_IDC,RUM_TypeFXDM4_IDC,RUM_TypeFXDM5_IDC,RUM_TypeFXDM6_IDC];
	for [{_n = 1},{_n <= 6},{_n = _n + 1}] do {
		_mun = _munlist select (_n - 1);
		_id = lbCurSel _mun;
		_text = lbText [_mun,_id];
		_payload = _payload + [_text];
	};
	_payload = _payload - ["N/A","None"];
   	_payload;
};

// Buttons ----------------------------
RUM_BttnStrike = {
	_id = _this select 1;
	switch (_id) do {
		case 0: {
			RUM_FXD_Strike = true;
		};
		case 1: {
			RUM_FXD_Strike = false;
		};
		case 2: {
			RUM_FXD_moveStation = true;
		};
	};
	if (true) exitwith {};
};

RUM_Stationed = {
	closedialog 0;
	[player] execVM (RUM_PATH+"Fxd\RUM_Fxd.sqf");
	if (true) exitwith {};
};

// Lists ------------------------------
RUM_TypeMUpdate1 = {
	private ["_arry","_tst","_num","_sel"];
	_arry = [];
	_tst = 0;
	_num = 0;
	while {dialog} do {
		_sel = lbCurSel RUM_ListFXD_IDC;
		if!(_sel == -1) then {
			if(RUM_FXD_NonSpawn)then{
				_arry = RUM_FXDAircraft select _sel;
				_num = _arry select 6;
			}else{
				_arry = RUM_FXDAircraft_Spawn select _sel;
				_num = _arry select 4;
			};
			if!(_sel == _tst)then{
				if(format ["%1",_num] == "any")then{_num = 0};
				_munlist = [RUM_TypeFXDM1_IDC,RUM_TypeFXDM2_IDC,RUM_TypeFXDM3_IDC,RUM_TypeFXDM4_IDC,RUM_TypeFXDM5_IDC,RUM_TypeFXDM6_IDC];
				{lbClear _x} foreach _munlist; 
				for [{_n  = 1},{_n <= _num},{_n = _n+1}] do {
					_mun = _munlist select (_n-1);
					_blist = ["None"] + RUM_FXD_bombList;
					{lbAdd [_mun,_x]} foreach _blist;
	   			};
	   			for [{_n = _num},{_n <= 5},{_n = _n+1}] do {
					_mun = _munlist select _n;
					lbAdd [_mun,"N/A"];
	   			};
	   		};
		};
	   	_tst = _sel;
	};
	if(true)exitWith{};
}; 


RUM_TypeMUpdate2 = {
	_arry = [];
	_tst = 0;
	_num = 0;
	while {dialog} do {
		_sel = lbCurSel RUM_ListFXD_IDC;
		if (!(_sel == -1)) then {
			_arry = RUM_FXDAircraft_onStation select _sel;
			_payload = _arry select 0;
			_num = count _payload;
			if (!(_sel == _tst)) then {
				if (format ["%1",_num] == "any") then {
					_num = 0;
				};
				_munlist = [RUM_TypeFXDM1_IDC,RUM_TypeFXDM2_IDC,RUM_TypeFXDM3_IDC,RUM_TypeFXDM4_IDC,RUM_TypeFXDM5_IDC,RUM_TypeFXDM6_IDC];
				{lbClear _x} foreach _munlist; 
				for [{_n = 1},{_n <= _num},{_n = _n + 1}] do {
					_mun = _munlist select (_n-1);
					{lbAdd [_mun,_x]} foreach ["None",_payload select (_n - 1)];
	   			};
	   			for [{_n = _num},{_n <= 5},{_n = _n + 1}] do {
					_mun = _munlist select _n;
					lbAdd [_mun,"N/A"];
	   			};
	   		};
	   	};
	   	_tst = _sel;
	};
	if (true) exitWith {};
};

RUM_FillListFXD1 = {
	lbClear RUM_ListFXD_IDC;
	_list1 = [];
	_airlist = [];
	if (RUM_FXD_NonSpawn) then {
		_airlist = RUM_FXDAircraft;
	} else {
		_airlist = RUM_FXDAircraft_Spawn;
	};
	for [{_n = 1},{_n <= (count _airlist)},{_n = _n + 1}] do {
		_air = _airlist select (_n - 1);
		_text = _air select 1;
		_list1 = _list1 + [_text];
   	};
	{lbAdd [RUM_ListFXD_IDC,_x]} foreach _list1;
	if (true) exitWith {};
};

RUM_FillListFXD2 = {
	lbClear RUM_ListFXD_IDC;
	_list1 = [];
	_airlist = RUM_FXDAircraft_onStation;
	for [{_n = 1},{_n <= (count _airlist)},{_n = _n + 1}] do {
		_air = _airlist select (_n - 1);	
		_arry = _air select 1;
		_text = _arry select 1;
		_list1 = _list1 + [_text];
   	};
	{lbAdd [RUM_ListFXD_IDC,_x]} foreach _list1;
	if (true) exitWith {};
};

RUM_MissType = {
	private "_tst";
	while {dialog} do {
		_sel = lbCurSel RUM_ListFXD_IDC;
		if (!(_sel == -1)) then {
			if (!(_sel == _tst)) then {
				private ["_types","_array"];
				if (RUM_FXD_idleorstation) then {
					if (RUM_FXD_NonSpawn) then {
						_array = RUM_FXDAircraft select _sel;
					} else {
						_array = RUM_FXDAircraft_Spawn select _sel;
					};
				} else {
					_lib = RUM_FXDAircraft_onStation select _sel;
					_array = _lib select 1;
				};
				lbClear RUM_FXDMISS_IDC;
				if ("cas" in _array) then {
					if ("cap" in _array) then {
						_types = ["Tactical Strike","Close Air Support","Combat Air Patrol"];
					} else {
						_types = ["Tactical Strike","Close Air Support"];
					};
				} else {
					if ("cap" in _array) then {
						_types = ["Tactical Strike","Combat Air Patrol"];
					} else {
						_types = ["Tactical Strike"];
					};
				};
				{lbAdd [RUM_FXDMISS_IDC,_x]} foreach _types;
				lbSetCurSel [RUM_FXDMISS_IDC, 0];
			};
		};
		_tst = _sel;
	};
	if (true) exitWith {};
};
//END Dialog Functions

RUM_FXD_weaponLoad = {
	_plane = _this;
	removeAllweapons _plane;
	{_plane removeMagazine _x} forEach magazines _plane;
	_weps = getArray (configFile>>"cfgVehicles">>typeOf _plane>>"weapons");
	{_plane addWeapon _x} forEach _weps;
	_mags = getArray (configFile>>"cfgVehicles">>typeOf _plane>>"magazines");
	{_plane addMagazine _x} forEach _mags;
//	hint format ["%1 %2",_mags,_weps];

	if ("AirBombLauncher" in weapons _plane) then {
		_plane removeWeapon "AirBombLauncher";
	};
	if ("BombLauncher" in weapons _plane) then {
		_plane removeWeapon "BombLauncher";
	};
	if ("BombLauncherA10" in weapons _plane) then {
		_plane removeWeapon "BombLauncherA10";
	};
	if ("BombLauncherF35" in weapons _plane) then {
		_plane removeWeapon "BombLauncherF35";
	};
	if ("Mk82BombLauncher" in weapons _plane) then {
		_plane removeWeapon "Mk82BombLauncher";
	};
	if ("Mk82BombLauncher_6" in weapons _plane) then {
		_plane removeWeapon "Mk82BombLauncher_6";
	};
};

if (true) exitwith {};
